bzoj 1041: [HAOI2008]圆上的整点 数学

1041: [HAOI2008]圆上的整点

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=1041

Description

求一个给定的圆(x^2+y^2=r^2),在圆周上有多少个点的坐标是整数。

Input

r

Output

整点个数

Sample Input

4

Sample Output

4

HINT

 n<=2000 000 000

题意

 

题解:

http://hzwer.com/1457.html

代码:

 

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)  
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************
ll r,ans;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int check(ll y,double x)
{
    if(x==floor(x))
    {
        ll x1=(ll)floor(x);
        if(gcd(x1*x1,y*y)==1&&x1*x1!=y*y)
            return 1;
    }
    return 0;
}
 
int main()
{
    r=read();
    for(ll i=1;i<=sqrt(2*r);i++)
    {
        if((2*r)%i==0)
        {
            for(ll a=1;a<=sqrt(r/i);a++)
            {
                double b=sqrt(((2*r)/i)-a*a);
                if(check(a,b))
                    ans++;
            }
            if(i!=(2*r)/i)
            {
                for(ll a=1;a<=sqrt(i/2);a++)
                {
                    double b=sqrt(i-a*a);
                    if(check(a,b))
                        ans++;
                }
                 
            }
        }
    }
    cout<<ans*4+4<<endl;
}

 

posted @ 2015-06-16 13:06  qscqesze  阅读(493)  评论(0编辑  收藏  举报